package dgut.lgc.Controller;

import dgut.lgc.bean.EpidemicSituation;
import dgut.lgc.service.AnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Controller
public class DisplayController {

    @Autowired
    private AnalysisService analysis;

    @RequestMapping("/")
    public String index() {
        return "index";
    }

    @ResponseBody
    @RequestMapping("/data/{PORS}/{CORR}")
    public List<EpidemicSituation> ReturnData(@PathVariable("PORS") String PORS, @PathVariable("CORR") String CORR) {
        System.out.println((PORS + " " + CORR));
        if (PORS==null||CORR==null) return new ArrayList<>();
        return analysis
                .getList()
                .stream()
                .filter(e -> PORS.equals("0") || e.getProvinceOrState().contains(PORS))
                .filter(e -> CORR.equals("0") || e.getCountryOrRegion().contains(CORR))
                .collect(Collectors.toList());
    }

    @ResponseBody
    @RequestMapping("/accumulate")
    public String accumulate(){
        return analysis.accumulateJson();
    }

    @ResponseBody
    @RequestMapping("/dayAdd")
    public String dayAdd(){
        return analysis.dayAddData();
    }

    @ResponseBody
    @RequestMapping("/countryTotal")
    public String countryTotal(){
        return analysis.countryOrRegionTotalNumber();
    }

    @ResponseBody
    @RequestMapping("/total")
    public String total(){
        return analysis.totalData();
    }
}
